// Web Worker脚本
import WasmRuntime from "./WasmRuntime.js";

self.onmessage = async (e) => {
  const { memory, start, end } = e.data;
  if (!start && !end) {
    return;
  }
  // 创建WasmRuntime实例
  const runtime = new WasmRuntime(memory);
  const wasm = await runtime.instantiate("./build/threads.wasm");

  const result = wasm.instance.exports.workerCompute(start, end);
  postMessage(result);
};
